package com.itheima.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

//@WebServlet(name = "StudentServlet")
public class StudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("13265465");

        //获取数据
        String username = request.getParameter("username");
        String age = request.getParameter("age");
        String score = request.getParameter("score");
        //保存数据
        BufferedWriter bw = new BufferedWriter(new FileWriter(getServletContext().getRealPath("/")+"\\stu.txt",true));
        bw.write(username+","+age+","+score);
        bw.newLine();
        bw.close();

        //返回信息
        PrintWriter writer = response.getWriter();
        writer.println("sava success!");
        writer.close();

    }
}
